package homes;


import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.joda.time.DateTime;
import org.springframework.orm.hibernate3.HibernateCallback;

import items.BrandDTO;
import items.Stockable;

@SuppressWarnings("serial")
public class StockableHome extends GenericHome<Stockable>{

	@Override
	protected Class<Stockable> getDomainClass() {
		return Stockable.class;
	}

	public List<Stockable> searchAccessories(final String accessoryType) {
	     return this.getHibernateTemplate().execute(new HibernateCallback<List<Stockable>>() {
	            public List<Stockable> doInHibernate(final Session session) throws HibernateException, SQLException {
	                Criteria criteria = session.createCriteria(Stockable.class);
	                criteria.add(Restrictions.eq("name", accessoryType));
	                return (List<Stockable>) criteria.list();
	            }
	        });
	}

	public List<Stockable> searchTires(final String string) {
		  return this.getHibernateTemplate().execute(new HibernateCallback<List<Stockable>>() {
	            public List<Stockable> doInHibernate(final Session session) throws HibernateException, SQLException {
	                Criteria criteria = session.createCriteria(Stockable.class);
	                criteria.add(Restrictions.eq("brand", string));
	                return (List<Stockable>) criteria.list();
	            }
	        });
	}


}
